package com.sm.user.controller;

import com.sm.tool.entity.request.PageInfo;
import com.sm.tool.entity.request.UserLoginRequest;
import com.sm.tool.entity.request.UserPhoneLoginRequest;
import com.sm.tool.entity.request.UserRegisterRequest;
import com.sm.tool.entity.response.ReturnData;
import com.sm.tool.entity.response.VerificationCode;
import com.sm.tool.entity.vo.UserDetailListVO;
import com.sm.tool.entity.vo.UserDetailVO;
import com.sm.user.service.UserRegLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: practice
 * @description: 用户登录注册controller
 * @author: liqitian.
 * @create: 2019-11-15 15:13
 **/
@RestController
@RequestMapping("api/v1/reglogin")
@Api(tags = "用户注册登录Api", value = "用户注册登录Api",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UserRegLoginController {

    @Autowired
    private UserRegLoginService userRegLoginService;

    /**
     * 用户注册
     * @param userRegisterRequest
     */
    @ApiOperation(value = "用户注册",produces =  MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/register")
    public ReturnData register(@Validated  @RequestBody UserRegisterRequest userRegisterRequest){
        return userRegLoginService.register(userRegisterRequest);
    }

    /**
     * 用户登录
     * @param userLoginRequest
     * @return
     */
    @ApiOperation(value = "用户登录，返回用户令牌",produces =  MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/login")
    public ReturnData login(@Validated  @RequestBody UserLoginRequest userLoginRequest) throws Exception {

        return userRegLoginService.login(userLoginRequest);
    }

    /**
     * 用户手机验证🐎登录
     * @param userPhoneLoginRequest
     * @return
     */
    @ApiOperation(value = "用户手机验证码登录，返回用户令牌",produces =  MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/phone_login")
    public ReturnData phoneLogin(@Validated  @RequestBody UserPhoneLoginRequest userPhoneLoginRequest) throws Exception {

        return userRegLoginService.phoneLogin(userPhoneLoginRequest);
    }

    /**
     * 获取注册验证码
     * @param phone
     * @return
     */
    @ApiOperation(value = "获取注册验证码，返回验证码（四位随机整数）",produces =  MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping("/get_register_validation_code/{phone}")
    public ReturnData<VerificationCode> getRegisterVerificationCode(@Validated @PathVariable String phone) {

        return userRegLoginService.getRegisterVerificationCode(phone);
    }

    /**
     * 获取登录验证码
     * @param phone
     * @return
     */
    @ApiOperation(value = "获取登录验证码，返回验证码（四位随机整数）",produces =  MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping("/get_login_validation_code/{phone}")
    public ReturnData<VerificationCode> getLoginVerificationCode(@Validated @PathVariable String phone) {

        return userRegLoginService.getLoginVerificationCode(phone);
    }
}
